﻿<%@ Page Title="" Language="C#" MasterPageFile="~/App_form/Menu/dao_tao.master" AutoEventWireup="true" CodeFile="pcgiangday.aspx.cs" Inherits="App_form_Daotao_pcgiangday" %>

<%@ Register TagPrefix="Control" TagName="menu_phai" Src="~/App_ctr/Admin/menu_phai.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <div style="width: 100%">
        <div style="width: 20%; float: left;">
            <Control:menu_phai runat="server" ID="menuphai" />
        </div>
        <div style="width: 79.4%; float: right;">
            <div style="background-image: url(../../CSS/images/ui-bg_glass_75_e6e6e6_1x400.png); font-weight: bold; height: 30px; border: 1px solid #d3d3d3; margin-top: 4px; text-align: center; padding-top: 8px; text-transform: uppercase;">
                Phân công giảng dậy
            </div>
            <div style="margin-top: 2px;">
                <div style="padding-left: 100px; padding-top: 20px; width: inherit; border: 1px solid #d3d3d3; height: 600px;">
                    <div style="width: 40%; float: left;">
                        <div style="float: left; width: 20%;">
                            <label>
                                Phòng  :
                            </label>
                        </div>
                        <div>
                            <Lib:drop runat="server" ID="phong" DataTextField="TEN" DataValueField="MA" Width="250px" Height="23px" onClientChange="PNS_NHAN_SU_LKE()"></Lib:drop>
                        </div>
                        <div style="width: 100%; height: 10px;"></div>
                        <div style="width: 100%;">
                            <Lib:gridView runat="server" ID="giangvien" Width="400" Height="200">
                                <Columns>
                                    <Lib:Column BaseColumn="HOVATEN" Name="Họ tên" Width="370" />
                                </Columns>
                                <Pager>
                                    <Lib:Pager PageSize="6" />
                                </Pager>
                            </Lib:gridView>
                        </div>
                    </div>
                    <div style="width: 57%; float: right;">
                        <div style="float: left; width: 20%;">
                            <label>
                                Bộ môn  :
                            </label>
                        </div>
                        <div>
                            <Lib:drop runat="server" ID="bomon" DataTextField="TEN" DataValueField="MA" Width="250px" Height="23px" onClientChange="PDT_BO_MON_LOP()"></Lib:drop>
                        </div>
                        <div style="width: 100%; height: 10px;"></div>
                        <div style="width: 100%;">
                            <Lib:gridView runat="server" ID="monhoc" Width="480" Height="200">
                                <Columns>
                                    <Lib:Column BaseColumn="chon" Name="Chọn" Width="40" EditControlType="CheckBox" />
                                    <Lib:Column BaseColumn="ten" Name="Tên" Width="200" />
                                    <Lib:Column BaseColumn="tiet" Name="Tiết(TC)" DataType="Number" Width="90" EditControlType="TextBox" />
                                    <Lib:Column BaseColumn="loai" Name="Loại" Width="70" lke="CB,CN" EditControlType="TextBox" />
                                    <Lib:Column BaseColumn="hso" Name="H.Số" Width="60" DataType="Number" EditControlType="TextBox" />
                                </Columns>
                                <Pager>
                                    <Lib:Pager PageSize="6" />
                                </Pager>
                            </Lib:gridView>
                        </div>
                    </div>
                    <div style="width: 100%; float: left; height: 26px; padding-top: 10px;">
                        <div style="float: left; width: 8%;">
                            <label>
                                Năm học:
                            </label>
                        </div>
                        <div style="float: left; width: 16%">
                            <Lib:drop runat="server" ID="namhoc" DataTextField="TEN" DataValueField="MA" Width="120px" Height="23px" onClientChange="P_PC_GIANGDAY_LKE()"></Lib:drop>
                        </div>
                    </div>
                    <div style="width: 100%; float: left; height: 26px; padding-top: 5px;">
                        <div style="float: left; width: 8%;">
                            <label>
                                Học kỳ :
                            </label>
                        </div>
                        <div style="float: left; width: 16%">
                            <Lib:drop runat="server" ID="hocky" DataTextField="TEN" DataValueField="MA" Width="120px" Height="23px" onClientChange="P_PC_GIANGDAY_LKE()"></Lib:drop>
                        </div>
                        <div style="float: left; width: 8%;">
                            <label>
                                Loại ĐT  :
                            </label>
                        </div>
                        <div style="float: left; width: 18%">
                            <Lib:drop runat="server" ID="loaidt" DataTextField="TEN" DataValueField="ID" Width="156px" Height="23px" onClientChange="PDT_KHOA_LKE()"></Lib:drop>
                        </div>
                        <div id="vh" style="display: none;">
                            <div style="float: left; width: 8%;">
                                <label>
                                    Lớp VH  :
                                </label>
                            </div>
                            <div style="float: left; width: 18%">
                                <Lib:drop runat="server" ID="lopvh" DataTextField="TEN" DataValueField="ID" Width="158px" Height="23px" onClientChange="PDT_VH_LKE()"></Lib:drop>
                            </div>
                            <div>
                                <Lib:Button runat="server" ID="Button1" Icon="LIST" Text="DS_SV" Width="100px" onClientClick="P_DS_SV_VHOA_LKE()"></Lib:Button>
                            </div>
                        </div>
                    </div>
                    <div id="tphu" style="width: 100%; float: left; height: 30px; padding-top: 10px; display: none;">
                        <div style="float: left; width: 8%;">
                            <label>
                                Tên phụ  :
                            </label>
                        </div>
                        <div style="float: left; width: 50%">
                            <Lib:textBox runat="server" ID="tenphu" Width="360px"></Lib:textBox>
                        </div>
                    </div>
                    <div style="width: 100%; padding-bottom: 10px; height: 27px;">
                        <div style="float: left; width: 8%;">
                            <label>
                                Khóa :
                            </label>
                        </div>
                        <div style="float: left; width: 16%">
                            <Lib:drop runat="server" ID="khoa" DataTextField="TEN" DataValueField="ID" Width="120px" Height="23px" onClientChange="PDT_KHOA_LOP()"></Lib:drop>
                        </div>
                        <div id="chonlop" style="float: left; width: 29%;">
                            <div style="float: left; width: 27%;">
                                <label>
                                    Lớp:
                                </label>
                            </div>
                            <div style="float: left; width: 20%">
                                <Lib:drop runat="server" ID="lop" DataTextField="TEN" DataValueField="ID" Width="160px" Height="23px" onClientChange="P_PC_GIANGDAY_LKE()" Style="margin-top: 0px"></Lib:drop>
                            </div>
                        </div>
                        <div style="float: left; width: 25%">
                            <Lib:Button runat="server" ID="add" Icon="ADD" Text="Thêm mới" Width="100px" onClientClick="P_PC_GIANGDAY_NH()"></Lib:Button>
                            <Lib:Button runat="server" ID="del" Icon="DEL" Text="Xóa" Width="100px" onClientClick="P_PC_GIANGDAY_XOA()"></Lib:Button>
                        </div>
                    </div>
                    <div style="width: 100%; float: left; margin-top: 10px;">
                        <Lib:gridView runat="server" ID="pcgiang" Width="880" Height="280">
                            <Columns>
                                <Lib:Column BaseColumn="giangvien" Name="Giảng viên" Width="300" />
                                <Lib:Column BaseColumn="lop" Name="Lớp" Width="250" />
                                <Lib:Column BaseColumn="monhoc" Name="Môn" Width="150" />
                                <Lib:Column BaseColumn="tiet" Name="Tiết(TC)" DataType="Number" Width="100" />
                                <Lib:Column BaseColumn="loai" Name="Loại" Width="70" lke="CB,CN" />
                                <Lib:Column BaseColumn="hso" Name="H.Số" Width="90" DataType="Number" />
                            </Columns>
                            <Pager>
                                <Lib:Pager PageSize="9" />
                            </Pager>
                        </Lib:gridView>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="dlg" class="easyui-dialog" title="Danh sách sinh viên " data-options="iconCls:'icon-save'" style="width: 600px; height: 410px; padding: 10px">
        <Lib:gridView runat="server" ID="dssv" Width="450" Height="400">
            <Columns>
                 <Lib:Column BaseColumn="lop" Name="Lớp" Width="200" />
                <Lib:Column BaseColumn="ma_sv" Name="Mã SV" Width="100" />
                <Lib:Column BaseColumn="ten" Name="Tên" Width="200" />
            </Columns>
            <Pager>
                <Lib:Pager PageSize="10" />
            </Pager>
        </Lib:gridView>
    </div>
    <asp:HiddenField ID="kthuoc" runat="server" Value="0,0" />
    <script>
        $("#dlg").dialog({ autoOpen: false });
        function P_DS_SV_VHOA_LKE() {
            var b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lopvh.ClientID%>").val();
            wdt_ma.FDT_SV_VHOA_LKE(b_nam, b_lop, P_SV_VHOA_LKE_KQ, ErrorDb, ErrorTimeOut);
        }
        function P_SV_VHOA_LKE_KQ(b_kq)
        {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            GetGridByID("<%=dssv.ClientID%>").dataBin(b_kq);
            $('#dlg').dialog({
                title: "Đăng ký văn hóa "+$("#<%=tenphu.ClientID%>").val(),
                width:490
            });
            $('#dlg').dialog("open");
        }

        function PDT_VH_LKE() {
            var b_tenlop = $("#<%=lopvh.ClientID%> option:selected").text();
            $("#<%=tenphu.ClientID%>").val(b_tenlop);

            //LKE PC giảng dậy lớp văn hóa
            //P_PC_GIANGDAY_LKE();
            b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
            var b_tenbm = $("#<%=bomon.ClientID%> option:selected").text();
            //Nếu là văn hóa
            if (b_tenbm.toUpperCase() == "VĂN HÓA") {
                b_okie = true;
                b_lop = $("#<%=lopvh.ClientID%>").val();
            }
            wdt_ma.FDT_PC_GIANGDAY_LKE(b_hk, b_nam, b_lop, P_PC_GIANGDAY_KQ, ErrorDb, ErrorTimeOut);
        }

        //PHONG
        function PNS_NHAN_SU_LKE() {
            try {
                var id_ph = $("#<%=phong.ClientID%>").val();
                wns.FNS_NHAN_SU_LKE(id_ph, P_NHAN_SU_LKE_KQ, ErrorDb, ErrorTimeOut);
                return false;
            }
            catch (err) {
                ShowError(err.message);
            }
        }
        function P_NHAN_SU_LKE_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetGridByID("<%=giangvien.ClientID%>");
            grid.dataBin(b_kq);
        }

        //BM_MON
        function PDT_BO_MON_LOP() {
            try {
                var bo_mon = $("#<%=bomon.ClientID%>").val();

                wdt_ma.FDT_MON_LKE(bo_mon, P_MON_LKE_KQ, ErrorDb, ErrorTimeOut);
                return false;
            }

            catch (err) {
                ShowError(err);
            }
        }
        function P_MON_LKE_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var b_tenbm = $("#<%=bomon.ClientID%> option:selected").text();
            //Nếu là văn hóa
            if (b_tenbm.toUpperCase() == "VĂN HÓA") {
                $("#vh").css("display", "block");
                $("#tphu").css("display", "block");
            }
            else {
                $("#vh").css("display", "none");
                $("#tphu").css("display", "none");
            }
            var grid = GetGridByID("<%=monhoc.ClientID%>");
            grid.dataBin(b_kq);
            P_PC_GIANGDAY_LKE();
            return false;
        }

        //KHOA
        function PDT_KHOA_LKE() {
            try {
                ht_dt = $("#<%=loaidt.ClientID%>").val()
                wdt_ma.FDT_KHOA_LKE(ht_dt, P_KHOA_LKE_KQ, ErrorDb, ErrorTimeOut);
                return false;
            }

            catch (err) {
                ShowError(err);
            }
        }
        function P_KHOA_LKE_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetGridByID("<%=khoa.ClientID%>");
            grid.dataBin(b_kq);
            PDT_KHOA_LOP();
            return false;
        }

        //KKHOA LOP
        function PDT_KHOA_LOP() {
            try {
                b_khoa = $("#<%=khoa.ClientID%>").val();
                if (Common.NVL(b_khoa, "") == "")
                    b_khoa = 0.0;
                wdt_ma.FDT_LOP_LKE(b_khoa, P_LOP_LKE_KQ, ErrorDb, ErrorTimeOut);
            }

            catch (err) {
                ShowError(err);
            }
        }
        function P_LOP_LKE_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetDropByID("<%=lop.ClientID%>");
            grid.dataBin(b_kq);
            P_PC_GIANGDAY_LKE();
            return false;
        }

        //LKE
        function P_PC_GIANGDAY_LKE() {
            try {
                b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
                var b_tenbm = $("#<%=bomon.ClientID%> option:selected").text();
                //Nếu là văn hóa
                if (b_tenbm.toUpperCase() == "VĂN HÓA") {
                    b_okie = true;
                    b_lop = $("#<%=lopvh.ClientID%>").val();
                    var b_tenlop = $("#<%=lopvh.ClientID%> option:selected").text();
                    $("#<%=tenphu.ClientID%>").val(b_tenlop);
                    wdt_ma.Fs_MON_VH_LKE(b_nam, P_MON_VH_LKE, ErrorDb, ErrorTimeOut);
                }
                wdt_ma.FDT_PC_GIANGDAY_LKE(b_hk, b_nam, b_lop, P_PC_GIANGDAY_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (err) {
                ShowError(err);
            }
        }

        function P_PC_GIANGDAY_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            b_nam = $("#<%=namhoc.ClientID%>").val();
            var b_tenbm = $("#<%=bomon.ClientID%> option:selected").text();
            //Nếu là văn hóa
            if (b_tenbm.toUpperCase() == "VĂN HÓA") {
                //wdt_ma.Fs_MON_VH_LKE(b_nam, P_MON_VH_LKE, ErrorDb, ErrorTimeOut);
            }

            var grid = GetGridByID("<%=pcgiang.ClientID%>");
            grid.dataBin(b_kq);
        }
        function P_MON_VH_LKE(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            GetDropByID("<%=lopvh.ClientID%>").dataBin(b_kq);
        }
        //Nhập
        function P_PC_GIANGDAY_NH() {
            try {
                b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val(),
                 phong_id = $("#<%=phong.ClientID%>").val();
                var grid_ns = GetGridByID("<%=giangvien.ClientID%>"), grid_mon = GetGridByID("<%=monhoc.ClientID%>");
                var a_ns = grid_ns.getValueActive(["NS_ID"]);
                var b_id_ns = "";
                if (a_ns.length < 0) {
                    Msg.Show("Cảnh báo", "Chưa chọn giảng viên", "error");
                    return;
                }
                b_id_ns = a_ns.NS_ID;
                var id_mon = [], a_tc = [], a_loai = [], a_hso = [];
                var a_data = grid_mon.getValueByCondition(["chon"], [true], ["=="]);
                var k = 0;
                var b_okie = false;
                var b_tenbm = $("#<%=bomon.ClientID%> option:selected").text();
                //Nếu là văn hóa
                var b_ten_phu = $("#<%=lop.ClientID%> option:selected").text();
                if (b_tenbm.toUpperCase() == "VĂN HÓA") {
                    b_okie = true;
                    b_lop = $("#<%=lopvh.ClientID%>").val();
                    b_ten_phu = $("#<%=tenphu.ClientID%>").val();
                }
                $.each(a_data, function (index, data) {
                    id_mon[k] = data.MA;
                    a_tc[k] = data.TIET;
                    a_loai[k] = data.LOAI;
                    a_hso[k] = data.HSO;
                    k++;
                });
               
                
                wdt_ma.FDT_PC_GIANGDAY_NH(phong_id, b_id_ns, b_hk, b_nam, b_lop, b_ten_phu, id_mon, a_tc, a_loai, a_hso, P_PC_GIANGDAY_NH_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (err) {
                ShowError(err);
            }
        }
        function P_PC_GIANGDAY_NH_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            P_PC_GIANGDAY_KQ(b_kq);
            PDT_BO_MON_LOP();
            Msg.Show("Thông báo", "Thêm thành công");
        }

        function P_PC_GIANGDAY_XOA() {
            try {
                var grid_ns = GetGridByID("<%=pcgiang.ClientID%>");
                var a_data = grid_ns.getValueActive();
                if (a_data.NS_ID == "") {
                    Msg.Show("Cảnh báo", "Chưa chọn giảng viên", "error");
                    return;
                }
                //double ns_id, string hk, double nam, double lop, double mon
                wdt_ma.FDT_PC_GIANGDAY_XOA(a_data.NS_ID, a_data.HK, a_data.NAM_ID, a_data.LOP, a_data.MON, P_PC_GIANGDAY_XOA_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (err) {
                ShowError(err);
            }
        }

        function P_PC_GIANGDAY_XOA_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            P_PC_GIANGDAY_LKE(b_kq);

        }
    </script>
</asp:Content>

